import 'package:flutter/material.dart';
import 'package:flutter_chat/pages/application/pages/contacts/view.dart';
import 'package:flutter_chat/pages/application/pages/find/view.dart';
import 'package:flutter_chat/pages/application/pages/user/view.dart';
import 'package:get/get.dart';
import 'package:ionicons/ionicons.dart';

import '../../common/style/theme.dart';
import '../../common/widget/app_bar/app_bar.dart';
import 'logic.dart';
import 'pages/message/view.dart';

class ApplicationPage extends GetView<ApplicationLogic> {
  const ApplicationPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      return Scaffold(
        appBar: customAppBar("APP", actions: [
          IconButton(
            onPressed: () {
              Get.toNamed("/login");
            },
            icon: const Icon(
              Icons.login,
            ),
          ),
        ]),
        body: _buildPageView(),
        bottomNavigationBar: _buildBottomNavigationBar(),
      );
    });
  }

  Widget _buildPageView() {
    return PageView(
      physics: const NeverScrollableScrollPhysics(),
      controller: controller.pageController,
      children: const [MessagePage(), ContactsPage(), FindPage(), UserPage()],
    );
  }

  Widget _buildBottomNavigationBar() {
    return BottomNavigationBar(
      backgroundColor: Colors.white,
      type: BottomNavigationBarType.fixed,
      currentIndex: controller.state.selectedPageIndex,
      selectedFontSize: AppTheme.smallFont,
      unselectedFontSize: AppTheme.smallFont,
      items: const [
        BottomNavigationBarItem(
          icon: Icon(Ionicons.chatbox_ellipses_outline),
          label: "消息",
        ),
        BottomNavigationBarItem(
          icon: Icon(Ionicons.people_outline),
          label: "联系人",
        ),
        BottomNavigationBarItem(
          icon: Icon(Ionicons.barbell),
          label: "发现",
        ),
        BottomNavigationBarItem(
          icon: Icon(Ionicons.person_outline),
          label: "我",
        )
      ],
      onTap: controller.onClickNavBar,
    );
  }
}
